/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * Main.java
 *
 * Created on September 20, 2005, 6:05 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package ptd;

import javax.swing.UIManager;
import ptd.PTDMain;

import java.net.URL;
import java.awt.Toolkit;
import java.awt.Dimension;
import javax.swing.SwingUtilities;

/**
 *
 * @author John
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
        int i = 10;
        
    }
    
    public static void makeDirs(){
        if(bDirsInitialized){
            return;
        }
        bDirsInitialized = true;
        
        //URL c = o.getClass().getProtectionDomain().getCodeSource().getLocation();
        URL c = Main.class.getProtectionDomain().getCodeSource().getLocation();
        
        AppDir = c.getPath();
        Main.debug_out(AppDir);
        AppDir = AppDir.replaceAll("%20", " ");
        
        // This may be required for non-windows OS... need a fix for this
        //AppDir = "/"+AppDir;
        
        int li = AppDir.lastIndexOf("/");
        AppDir = AppDir.substring(1, li);
        ImageDir = AppDir + "/images";
        HelpDir = AppDir + "/help";
    }
    
    private static String AppDir;
    private static String HelpDir;
    private static String ImageDir;
    private static PTDMain MainFrame;
    private static boolean bDirsInitialized = false;
    
    public static boolean bDebugOut = false;
    
    // Nice ditty on synchronization http://supportweb.cs.bham.ac.uk/documentation/java/tutorial/native1.1/implementing/sync.html
    public static String sSyncObject = "SyncObject";  // Used to synchronize so two scripts cannot be run concurrently
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        makeDirs();

        
        // Cant do UI Manager Stuff Here because of trees
        //try{
        //    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        //}catch(Exception e){
        //    Main.debug_out(e.getMessage());
        //}


        
        
        //PTDMessageBox aMessage = new PTDMessageBox("See");
        //aMessage.setVisible(true);

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();       

        //try{
        //    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //}catch(Exception e){
        //    Main.debug_out(e.getMessage());
        //}
        //SwingUtilities.updateComponentTreeUI(MainFrame);
        //MainFrame.pack();

        
        PTDSplashScreen a = new PTDSplashScreen(dim.width/2, dim.height/2);
        MainFrame = new PTDMain();
        MainFrame.setSize(dim.width-50,dim.height-50);
        MainFrame.setVisible(true);
        a.start_timer();
    }

    //public static void jvm_main() {
    //    MainFrame = new PTDMain();        
    //    
    //    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //    
    //    MainFrame.setSize(dim.width-30,dim.height-40);
    //    MainFrame.setVisible(true);
    //}    
    
    public static String getAppDir(){
        return AppDir;
    }

    public static String getHelpDir(){
        return HelpDir;
    }
    
    public static String getImageDir(){
        return ImageDir;
    }
    
    public static PTDMain getMainFrame(){
        return MainFrame;
    }
    
    public static void debug_out(String s){
        if(bDebugOut){
            System.out.println("DEBUG OUT: " + s);
        }
    }
    
}
